package com.redis.example.service.impl;

import com.redis.example.bean.User;
import com.redis.example.service.UserService;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author H
 * @date 2023/1/4
 */
@Service
public class UserServiceImpl implements UserService {

    @Override
    @CachePut(value = "redisCache", key = "'redis_user_' + #result.id")
    public User testInsertCache() {
        User user = new User();
        user.setId(1L);
        user.setUsername("小明");
        user.setEmail("123@qq.com");
        return user;
    }

    @Override
    @Cacheable(value = "redisCache", key = "'redis_user_' + #result.id")
    public User testGetCache() {
        User user = new User();
        user.setId(1L);
        user.setUsername("小明");
        user.setEmail("123@qq.com");
        return user;
    }
}
